#include "../pch.h"

namespace BFX
{

REFXMLChildList::REFXMLChildList(const REFXMLNode* pContainer)
{
	BFX_ASSERT(pContainer != NULL);
	m_pContainer = pContainer;
}

REFXMLNode* REFXMLChildList::operator[](int iIndex) const
{
	// Out of range indexes return a NULL
	if (iIndex < 0)
		return NULL;

	for (REFXMLNode* p = m_pContainer->GetFirstChild(); p != NULL; p = p->GetNextSibling(), iIndex --)
	{
		if (iIndex == 0)
			return p;
	}

	return NULL;
}

REFXMLNode* REFXMLChildList::GetItem(int nIndex) const
{
	return (*this)[nIndex];
}

int REFXMLChildList::GetCount() const
{
	// TODO: need to optimize!
	int nCount = 0;
	for (REFXMLNode* p = m_pContainer->GetFirstChild(); p != NULL; p = p->GetNextSibling())
	{
		nCount ++;
	}
	return nCount;
}

}	//	namespace BFX
